<?php

namespace Application\Form;

use Zend\Form\Form;
use Application\Model\Contact;
use Zend\Captcha;
use Zend\Form\Element;
use Zend\Log\Logger;


class ContactForm extends Form
{
	public function __construct()
	{
		
		parent::__construct("Contact_Form");
		 
		$this->setAttribute('method', 'post');
		 
		$this->add(array(
				'name' => 'id',
				'attributes' => array(
						'type'  => 'hidden',
				),
		));
		 
		$this->add(array(
				'name' => 'nom',
				'attributes' => array(
						'type'  => 'text',
				),
				'options' => array(
						'label' =>_('Nom'),
				),
		));
		
		$this->add(array(
				'name' => 'prenom',
				'attributes' => array(
						'type'  => 'text',
				),
				'options' => array(
						'label' => _('Prénom'),
				),
		));
		
		$this->add(array(
				'name' => 'objet',
				'attributes' => array(
						'type'  => 'text',
				),
				'options' => array(
						'label' => _('Objet'),
				),
		));
		 
	/*	$this->add(array(
				'type' => 'Zend\Form\Element\Select',
				'name' => 'sexe',
				'options' => array(
						'label' => 'Sexe',
						'value_options' => array(
								'1' => 'Votre sexe',
								'2' => 'Feminin',
								'3' => 'Masculin'
						),
				),
				'attributes' => array(
						'value' => '1' //set selected to '1'
				)
		));*/
		 
		 
		$this->add(array(
				'type' => 'Zend\Form\Element\Email',
				'name' => 'email',
				'options' => array(
						'label' => _('Email'),
				),
				'attributes' => array(
						'placeholder' => 'you@domain.com'
				)
		));

		$this->add(array(
				'name' => 'tel',
				'attributes' => array(
						'type'  => 'text',
				),
				'options' => array(
						'label' => _('Téléphone'),
				),
		));
		
		
// 		$this->add(array(
// 				'type' => 'Zend\Form\Element\Number',
// 				'name' => 'tel',
// 				'options' => array(
// 						'label' => 'Phone Number',
// 				)
// 		));
		
		$this->add(array(
				'name' => 'addresse',
				'attributes'=>array(
						'type'=>'textarea'
				),
				'options' => array(
						'label' => _('Addresse'),
						
				),
		));
		 
		
		$this->add(array(
				'name' => 'message',
				'attributes'=>array(
						'type'=>'textarea'
				),
				'options' => array(
						'label' => _('Message'),
				),
		));
		
	
	/*	$captcha = new Element\Captcha('captcha');
		$captcha->setCaptcha(new Captcha\Dumb());
		$captcha->setLabel('Recopier ce texte');
		
	//	$csrf = new Element\Csrf('security');
		$this->add($captcha);
		//$this->add($csrf);
		
	*/	
		$this->add(array(
				'name' => 'submit',
				'attributes' => array(
						'type'  => 'submit',
						'width' => '30px',
						'value' => 'Envoyer',
						'id' => 'submitbutton',
				),
		));
	}
	 
	
	//IF YOU WILL WORK WITH DATABASE
	//AND NEED bind() FORM FOR EDIT DATA, YOU NEED OVERRIDE
	//populateValues() FUNC LIKE THIS
	public function populateValues($data)
	{
		foreach($data as $key=>$row)
		{
			if (is_array(@json_decode($row))){
				$data[$key] =   new \ArrayObject(\Zend\Json\Json::decode($row), \ArrayObject::ARRAY_AS_PROPS);
			}
		}
		 
		parent::populateValues($data);
	}
}

?>